package com.example.wallpaperapp.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;


import com.example.wallpaperapp.R;
import com.example.wallpaperapp.adapter.TitleFragmentPagerAdapter;
import com.example.wallpaperapp.ui.fragment.MonthFragment;
import com.example.wallpaperapp.ui.fragment.SumFragment;
import com.example.wallpaperapp.ui.fragment.WeekFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class ListActivity extends AppCompatActivity implements  ViewPager.OnPageChangeListener , View.OnClickListener {
    private ViewPager mViewpager;
    List<Fragment> fragments;
    private  TabLayout mTabLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        mViewpager = findViewById(R.id.list_viewpager);
        mTabLayout = findViewById(R.id.tab);

        ImageView imageButton=findViewById(R.id.back);
        imageButton.setOnClickListener(this);
        initViewPager();
    }

    private void initViewPager() {
        fragments = new ArrayList<>();
        fragments.add(new WeekFragment());
        fragments.add(new MonthFragment());
        fragments.add(new SumFragment());

        mViewpager.setAdapter(new TitleFragmentPagerAdapter(getSupportFragmentManager(),  fragments,new String[]{"周榜", "月榜", "总榜"}));
        mViewpager.addOnPageChangeListener(this);
        mTabLayout.setupWithViewPager(mViewpager);
        mViewpager.setCurrentItem(0);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }




    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            default:
                break;
        }
    }
}
